<template>
  <div id="attach" style="width: 100%; justify-content: center; display: flex">
    <div style="width: 100%;">
      <div>
        <a-table
          :columns="columns"
          :data-source="histories"
          rowKey="id"
          bordered
          :pagination="ipagination"
          @change="handleTableChange"
        >
          <span slot="action" slot-scope="text, record">
            <a icon="download" @click="viewHistory(record)">查阅</a>
          </span>
        </a-table>
      </div>
    </div>
  </div>
</template>

<script>
import { getAction } from '@/api/manage'
export default {
  components: {},
  props: {
    parentId: {
      type: String,
      default: 0,
    },
  },
  data() {
    return {
      columns: [
        {
          title: '文件编号',
          dataIndex: 'fileNoStr',
          key: 'fileNoStr',
        },
        {
          title: '文件名称',
          dataIndex: 'fileName',
          key: 'fileName',
        },
        {
          title: '版本',
          key: 'version',
          dataIndex: 'version',
        },
        {
          title: '发布时间',
          key: 'effectTime',
          dataIndex: 'effectTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 145,
          scopedSlots: { customRender: 'action' },
        },
      ],
      histories: [],
      urls: {
        historyList: '/lib/hteLibFile/historyList',
      },
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        id: 0,
        total:0
      },
      fileId : 0
    }
  },
  created() {},
  methods: {
    /**
     * 获取历史版本列表
     */
    fetchHistories(fileId) {
      this.fileId = fileId;
      this.ipagination.id = fileId
      let that = this
        let param = Object.assign({},this.ipagination);
      delete param.pageSizeOptions
      delete param.showTotal
      getAction(this.urls.historyList, param).then((res) => {
        if (res.success) {
          this.histories = res.result.records || res.result
          if (res.result.total) {
            that.ipagination.total = res.result.total
          } else {
            that.ipagination.total = 0
          }
          that.$emit("getTotal",that.ipagination.total)
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
      })
    },
    viewHistory(record) {
      let urlJump = this.$router.resolve({ path: '/library/file/view/' + this.parentId + '/' + record.fileId + '/' + record.draftVersion })
      window.open(urlJump.href, '_blank')
    },
    /**
     * 表结构切换页码
     */
    handleTableChange(pagination, filters, sorter) {
      this.ipagination = pagination
      this.ipagination.pageNo = this.ipagination.current
      this.fetchHistories( this.fileId)
    },
  },
}
</script>

<style>
.attr-box {
  width: 100%;
  /* display: flex;
  align-content: flex-start;
  flex-flow: row wrap; */
}

/* .attr-item {
  width: 50%;
  margin-bottom: 20px;
} */
</style>